import java.util.Iterator;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import com.chimoz.lauwsys.business.BrandManager;
import com.chimoz.lauwsys.domain.Brand;

/**
 * @project lauwsys
 */

/**
 * @author Christian Teguh
 * @created 4 Okt 2011 00.31.21
 */
public class MainLauwSys {

	private ApplicationContext context;
	
	private BrandManager brandManager;
	
	
	public MainLauwSys() {
		context = new ClassPathXmlApplicationContext("db/lauwsys-hibernate.xml");
		brandManager = (BrandManager) context.getBean("simpleBrandManager");
	}

	public void getBrandById(Long id) {
		Brand brand = this.brandManager.getBrandById(id);
		System.out.println(brand);
	}
	
	public void insertBrand(){
		Brand brand = new Brand();
		brand.setName("Criket");
		brand.setDesc("Korek api");
		Brand newBrand = this.brandManager.createBrand(brand);
		System.out.println(newBrand.getId() + " - " + newBrand + " - " + newBrand.getCtime() + " - " + newBrand.getMtime());
	}
	
	public void updateBrand(Long id){
		Brand brand = new Brand(id);
		brand.setName("Criketttttttttttt");
		brand.setDesc("KOREK API");
		Brand newBrand = this.brandManager.editBrand(brand);
		System.out.println(newBrand.getId() + " - " + newBrand + " - " + newBrand.getCtime() + " - " + newBrand.getMtime());
	}
	
	public void getAllBrand() {
//		List<Brand> brands = this.brandManager.listBrand();
//		
//		for ( Iterator<Brand> it = brands.iterator(); it.hasNext(); ) {
//			Brand newBrand = it.next();
//			System.out.println(newBrand.getId() + " - " + newBrand + " - " + newBrand.getCtime() + " - " + newBrand.getMtime());
//		}
	}
	
	public static void main(String args[]) {
		MainLauwSys mlj = new MainLauwSys();
		mlj.getBrandById(new Long(args[0]));
//		mlj.insertBrand();
//		mlj.updateBrand(new Long(args[0]));
//		mlj.getAllBrand();
	}
}
